package me.youline.dataServer.service.support;

/**
 * 业务后台日志信息生成器，以用来生成规格化的日志，方便查询与调试
 * @author linhan
 *
 */
public class LogMsgBuilder {
	
	private LogMsg logMsg = new LogMsg();
	
	private static final String MSG_FORMAT = "[%s][%s][%s]{msg:%s,detail:%s}";
	
	public static LogMsgBuilder build(){
		return new LogMsgBuilder();
	}
	
	public LogMsgBuilder info(){
		logMsg.setLogEvent("INFO");
		return this;
	}
	
	public LogMsgBuilder error(){
		logMsg.setLogEvent("ERROR");
		return this;
	}
	
	public LogMsgBuilder module(String name){
		logMsg.setModuleName(name);
		return this;
	}
	
	public  LogMsgBuilder interfaceName(String interfaceName){
		logMsg.setInterfaceName(interfaceName);
		return this;
	}
	
	public LogMsgBuilder msg(String msg){
		logMsg.setMsg(msg);
		return this;
	}
	
	public LogMsgBuilder detail(String detail){
		logMsg.setDetail(detail);
		return this;
	}
	
	public String getLogInfo(){
		return String.format(MSG_FORMAT, logMsg.getLogEvent(),logMsg.getModuleName(),logMsg.getInterfaceName(),logMsg.getMsg(),logMsg.getDetail());
		
	}
	
	
	public static class LogMsg{
		
		private String logEvent= "";
		
		private String moduleName = "";
		
		private String interfaceName = "";
		
		private String msg = "";
		
		private String detail = "";

		public String getLogEvent() {
			return logEvent;
		}

		public void setLogEvent(String logEvent) {
			this.logEvent = logEvent;
		}

		public String getModuleName() {
			return moduleName;
		}

		public void setModuleName(String moduleName) {
			this.moduleName = moduleName;
		}

		public String getInterfaceName() {
			return interfaceName;
		}

		public void setInterfaceName(String interfaceName) {
			this.interfaceName = interfaceName;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}

		public String getDetail() {
			return detail;
		}

		public void setDetail(String detail) {
			this.detail = detail;
		}
		
	}
	
	
	
}
